# Contributor: Oleg Titov <oleg.titov@gmail.com>
# Maintainer: Oleg Titov <oleg.titov@gmail.com>
pkgname=mwoffliner
pkgver=1.11.10
pkgrel=0
pkgdesc="Scrape any online Mediawiki motorised wiki to your local filesystem"
url="https://github.com/openzim/mwoffliner"
arch="x86_64"
license="GPL-3.0-or-later"
options="!check" # no test suite from upstream
depends="npm redis libc6-compat"
makedepends="python3 autoconf automake chrpath libjpeg-turbo-dev nasm zlib-dev
	libzim-dev bash"
subpackages="$pkgname-doc"
source="mwoffliner-$pkgver.tar.gz::https://github.com/openzim/mwoffliner/archive/v$pkgver.tar.gz"

build() {
	npm install
}

check() {
	npm test
}

package() {
	install -d "$pkgdir"/usr/share/doc/$pkgname "$pkgdir"/usr/lib/node_modules/$pkgname
	cp -a lib node_modules package*.json "$pkgdir"/usr/lib/node_modules/$pkgname
	ln -s /usr/lib/node_modules/$pkgname/bin/$pkgname "$pkgdir"/usr/lib/node_modules/$pkgname

	install -Dm644 README.md "$pkgdir/usr/share/doc/$pkgname/README.md"

	# Strip all the rpath that include /home
	local scandir="$pkgdir"/usr/lib/node_modules/mwoffliner/node_modules/@openzim/libzim/
	scanelf --recursive --rpath --etype ET_DYN "$scandir" | \
		awk '/home/{print $3;}' | xargs chrpath --delete
}

sha512sums="
d9a820327343a41f21df93c40ebe682ddf91cc18431399d712a6f1e7830192e13b18a677cc2639f6a0aa36518782c0581d2a6991ff5f744cef9fb91c3433e025  mwoffliner-1.11.10.tar.gz
"
